/*
 * COPYRIGHT:	2010 Christopher Smith, licenced under the GNU GPL v2; see COPYING in the top level directory
 * PROJECT:		sdedit
 * FILE:		errortaskdialog.cpp
 * PURPOSE:		TaskDialog support on Vista, as an alternative to errordialog.cpp's implementation
 *				requires Vista's version of commctrl v6 to be available in the binary's manifest
 */

namespace ErrorTaskDialog
{
//
//struct TASKDIALOG_BUTTON_noheader
//{
//    int nButtonID;
//    PCWSTR pszButtonText;
//};
//
//struct TASKDIALOGCONFIG_noheader
//{
//    UINT cbSize;
//    HWND hwndParent;
//    HINSTANCE hInstance;
//    ULONG dwFlags;
//    ULONG dwCommonButtons;
//    PCWSTR pszWindowTitle;
//    union {
//        HICON hMainIcon;
//        PCWSTR pszMainIcon;
//    };
//    PCWSTR pszMainInstruction;
//    PCWSTR pszContent;
//    UINT cButtons;
//    const TASKDIALOG_BUTTON_noheader *pButtons;
//    int nDefaultButton;
//    UINT cRadioButtons;
//    const TASKDIALOG_BUTTON_noheader *pRadioButtons;
//    int nDefaultRadioButton;
//    PCWSTR pszVerificationText;
//    PCWSTR pszExpandedInformation;
//    PCWSTR pszExpandedControlText;
//    PCWSTR pszCollapsedControlText;
//    union {
//        HICON hFooterIcon;
//        PCWSTR pszFooterIcon;
//    };
//    PCWSTR pszFooter;
//    PVOID pfCallback;
//    LONG_PTR lpCallbackData;
//    UINT cxWidth;
//};

DelayedImportFunction<HRESULT (WINAPI *)(const TASKDIALOGCONFIG *, int *, int *, BOOL *)> TaskDialogIndirect_delayed(L"comctl32.dll", "TaskDialogIndirect");

int CALLBACK ShowErrorMessageBox(PCWSTR Title, PCWSTR Text, HWND Parent, BOOLEAN Noncontinuable, BOOLEAN CanCancel)
{
	TASKDIALOG_BUTTON Buttons[] = {
		{IDABORT, L"Abort\nAbort all pending operations"},
		{IDIGNORE, L"Ignore\nIgnore this specific error, continue any pending operations"},
		{IDRETRY, L"Retry\nRetry this operation"}};

	TASKDIALOGCONFIG Config = {
		sizeof(TASKDIALOGCONFIG),
		Parent,
		SdEditGModule,
		TDF_USE_COMMAND_LINKS,
		0, //no standard buttons
		Title,
		NULL, //no title icon
		L"", //no main message
		Text,
		0, //filled in below
		Buttons,
		IDIGNORE, //IDIGNORE is default
		0, //zero radio buttons
		NULL, //no radio button array
		NULL, //no verification text
		NULL, //no expanded info
		NULL, //no expand button
		NULL, //no collapse button
		NULL, //no footer icon
		NULL, //no callback func
		0, //no callback data
		0}; //auto width

	if(!Noncontinuable && CanCancel)
		Config.cButtons = 3;
	else if(CanCancel)
		Config.cButtons = 2;
	else
		Config.cButtons = 1;

	int Ret;
	HRESULT Result = TaskDialogIndirect_delayed(&Config, &Ret, NULL, NULL);

	if(FAILED(Result))
		return ErrorDialog::ShowErrorMessageBox(Title, Text, Parent, Noncontinuable, CanCancel); //fallback
	else
		return Ret;
}

}//namespace ErrorTaskDialog